﻿///***************************************************************
/// 시  스  템 : Updms.Fit
/// 단위시스템 : FIT
/// 계      층 : Presentation Layer
/// 프로그램명 : Fit3013p
/// 파  일  명 : Fit3013p.aspx.cs
/// 설      명 : 트레이닝아이디 수정팝업
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2015-01-12 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Data;

using Base.Dac;
using Base.AppFramework.Web.UI.CommandBar;

using Updms.Fit.Exe;


namespace Updms.Fit
{
	public partial class Fit3013p : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		public static readonly string PID = "Fit3013p";
		public static readonly string gs_path_info = "/updms/Fit/" + PID + ".aspx";

		Global global = new Global();

		private string kw1 = ""; //기존 트레이닝아이디

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SetTrainingIdList();
				SearchProcess();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetSearchParameter

		//검색파라미터
		private void SetSearchParameter()
		{
			kw1 = string.IsNullOrEmpty(Request.QueryString["asis_training_id"]) ? "" : Request.QueryString["asis_training_id"].ToString();
		}

		#endregion

		#region 디테일 Method (SetTrainingIdList)

		private void SetTrainingIdList()
		{
			DataPack lo_dp = new DataPack();
			DataSet lo_ds = new DataSet();

			lo_dp.AddProperty("asis_training_id", typeof(string), kw1);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
			
			Fit3013p_NT _Fit3013p_NT = new Fit3013p_NT();
			lo_ds.Merge(_Fit3013p_NT.GetTrainingIdList(lo_dp));

			ddl_training_id.Items.Clear();
			ddl_training_id.DataSource = lo_ds;
			ddl_training_id.DataMember = "UPDMS_FIT_WEIGHT_TRAINING";
			ddl_training_id.DataTextField = "Text";
			ddl_training_id.DataValueField = "Value";
			ddl_training_id.DataBind();
			ddl_training_id.Items.Insert(0, new ListItem(DDL_SELECT, ""));
		}

		#endregion

		#region CRUD (SelectProcess, UpdateProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			ddl_training_id.SelectedValue = kw1;
			lbl_search_keyword.Text = kw1;
		}

		//수정
		private void UpdateProcess()
		{
			using (Fit3013p_RT _Fit3013p_RT = new Fit3013p_RT())
			{
				int li_return = _Fit3013p_RT.ChangeTrainingId(SetValue());
				string ls_msg_id = (li_return > 0) ? "MSG_INF_010" : "MSG_ERR_110";	//변경되었습니다:변경할 수 없습니다
				string ls_msg_tp = (li_return > 0) ? "ICR" : "AC";

				CallMsgBoxInAjax(ls_msg_id, null, ls_msg_tp);
			}
		}

		//검색
		private void SearchProcess()
		{
			SetSearchParameter();
			SelectProcess();
		}

		#endregion

		#region SetValue

		//SetValue
		private DataPack SetValue()
		{
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("asis_training_id", typeof(string), kw1);
			lo_dp.AddProperty("tobe_training_id", typeof(string), ddl_training_id.SelectedValue);
			lo_dp.AddProperty("ls_user_id", typeof(string), USER_ID);

			return lo_dp;
		}

		#endregion

		#region Page_PreRender

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
			}
		}

		#endregion

		#region 버튼이벤트

		//저장
		protected void ibtn_save_Click(object sender, EventArgs e)
		{
			SetSearchParameter();
			UpdateProcess();
		}

		#endregion

	}
}